﻿using System.ComponentModel;
using System.Diagnostics;
using System;
using UtfprLibrary.Exceptions;

namespace UtfprLibrary.Helpers {
    public static class DesignTimeHelper {
        /// <summary>
        /// Check if the system is in design mode.
        /// </summary>
        /// <exception cref="UtfprLibrary.Exceptions.UtfprHelpersException">Thrown when an exception occurs.</exception>
        public static bool IsInDesignMode {
            get {
                try {
                    bool isInDesignMode = LicenseManager.UsageMode == LicenseUsageMode.Designtime;

                    if (!isInDesignMode) {
                        using (var process = Process.GetCurrentProcess()) {
                            return process.ProcessName.ToLowerInvariant().Contains("devenv");
                        }
                    }

                    return isInDesignMode;
                } catch (Exception ex) {
                    throw new UtfprHelpersException(Properties.Resources.Helpers_DesignTimeHelper_ExMsg_IsInDesignMode, ex);
                }
            }
        }
    }
}
